package com.changgou.backend.controller;

import com.changgou.entity.QueryPageBean;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.feign.SkuFeign;
import com.changgou.goods.feign.SpuFeign;
import com.changgou.goods.pojo.Sku;
import com.changgou.goods.pojo.Spu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author xuchangshuo
 * @date 2020/7/26 16:09
 */

@Controller
@RequestMapping("/findGoods")
public class GoodsController {
    @Autowired
    private SpuFeign spuFeign;


    @Autowired
    private SkuFeign skuFeign;


//    @RequestMapping("/findPageGoods")
//    @ResponseBody
//    public Result findPageGoods() {
//        Result result = spuFeign.queryPage();
//        return result;
//    }

    //根据id查询商品
    @RequestMapping("/findById")
    public Result findById(@RequestParam("id") String id) {
        Result<Spu> data = spuFeign.findSpuById(id);
        Spu spu = data.getData();
        return new Result(true, StatusCode.OK, "查询成功", spu);
    }

//    //跳转商品页面
//    @RequestMapping("/toGoods")
//    public String toGoods() {
//        return "goods";
//    }
//
//    //跳转主页面
//    @RequestMapping("/toMain")
//    public String toMain() {
//        return "main";
//    }
//    //回收站页面
//    @RequestMapping("/toTrach")
//    public String toTrach() {
//        return "trash";
//    }

    //删除商品 逻辑删除将isDelete状态修改为1
    @ResponseBody
    @RequestMapping("/delete")
    public Result delete2Trash(@RequestParam("id") String id) {
        return spuFeign.delete(id);
    }

    //商品审核
    @RequestMapping("/check")
    @ResponseBody
    public Result check(@RequestParam("id") String id, @RequestParam("status") String status) {
        spuFeign.audit(id, status);

        return new Result(true, StatusCode.OK, "审核通过");
    }

    //商品上下架
    @RequestMapping("/marketable")
    @ResponseBody
    public Result marktable(@RequestParam String id, @RequestParam String marketable) {
        Result result = spuFeign.marketable(id, marketable);
        return result;
    }

    //    设置商品数量/
    @RequestMapping("/updateNum")
    @ResponseBody
    public Result updateNum() {
        return new Result();
    }

    //查询商品
    @RequestMapping("/findPageGoods1")
    @ResponseBody
    public Result queryPage(@RequestBody QueryPageBean queryPageBean) {
        Result result = spuFeign.findPage1(queryPageBean);
        return result;
    }

    //根据spuId查询spu
    @RequestMapping("/findSpuBySpuId")
    @ResponseBody
    public Result findBySpuId(@RequestParam String id) {
        return spuFeign.findSpuById(id);
    }


    //根据spuId查询sku
    @RequestMapping("/findSkuBySpuId")
    @ResponseBody
    public Result findSkuBySpuId(@RequestParam String id) {
        List<Sku> skuList = skuFeign.findSkuListBySpuId(id);
        return new Result(true, StatusCode.OK, "查询成功", skuList);
    }


    //审核商品
    @ResponseBody
    @RequestMapping("/aduit")
    public Result aduit(@RequestParam String id, @RequestParam String status) {
        Result result = spuFeign.audit(id, status);
        return result;
    }

//    //添加商品
//    @ResponseBody
//    @RequestMapping("/add")
//    public Result add(@RequestBody Spu spu) {
//        spuFeign.add(spu);
//        return null;
//    }


}
